package net.oschina.app.adapter.center_message;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import net.oschina.app.R;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.bean.MessagesBean;
import net.oschina.app.util.CommonUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by elf on 2017/1/16.
 * 我---消息界面----留言界面
 */

public class NewsMessageAdapter extends BaseAdapter {
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(CommonUtils.getContext()).inflate(R.layout.item_news_message, parent, false);
        NewsMessageHolder newsMessageHolder = new NewsMessageHolder(itemView);
        return newsMessageHolder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        NewsMessageHolder newsMessageHolder = (NewsMessageHolder) holder;
        MessagesBean.MessageBean messageBean = (MessagesBean.MessageBean) mDatas.get(position);
        Glide.with(CommonUtils.getContext()).load(messageBean.getPortrait()).into(newsMessageHolder.mIvUserMessage);
        newsMessageHolder.mTvUserNameMsg.setText(messageBean.getFriendname());
        newsMessageHolder.mTvContent.setText(messageBean.getContent());
        newsMessageHolder.mTvDateMsg.setText(messageBean.getPubDate());
        newsMessageHolder.mTvMsgCount.setText(messageBean.getMessageCount()+"条留言");
    }

    static class NewsMessageHolder extends RecyclerView.ViewHolder{
        @BindView(R.id.iv_user_message)
        CircleImageView mIvUserMessage;
        @BindView(R.id.tv_user_name_msg)
        TextView mTvUserNameMsg;
        @BindView(R.id.tv_content)
        TextView mTvContent;
        @BindView(R.id.tv_date_msg)
        TextView mTvDateMsg;
        @BindView(R.id.tv_msg_count)
        TextView mTvMsgCount;

        NewsMessageHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
